/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.core.search;

import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Icon;

import org.kommando.core.Displayable;
import org.kommando.core.util.Assert;
import org.kommando.ui.IconHelper;

/**
 * @author Peter De Bruycker
 */
public abstract class AbstractResult<T extends Displayable> implements Result<T> {

    // TODO test this class (icon scaling)

    private T value;

    private Map<Dimension, Icon> scaledIcons = new HashMap<Dimension, Icon>();

    public AbstractResult(T value) {
        Assert.argumentNotNull("value", value);

        this.value = value;
    }

    @Override
    public T getValue() {
        return value;
    }

    @Override
    public String getDescription() {
        return value.getDescription();
    }

    @Override
    public String getName() {
        return value.getName();
    }

    @Override
    public Icon getIcon() {
        return value.getIcon();
    }

    public Icon getIcon(Dimension size) {
        if (!scaledIcons.containsKey(size)) {
            scaledIcons.put(size, IconHelper.getIcon(this, size));
        }

        return scaledIcons.get(size);
    }

    // @Override
    // public boolean equals(Object obj) {
    // if (obj instanceof Result) {
    // Result<?> other = getClass().cast(obj);
    //
    // Object thisValue = value;
    // Object otherValue = other.value;
    //
    // return thisValue.equals(otherValue);
    // }
    // return false;
    // }
    //
    // @Override
    // public int hashCode() {
    // return value.hashCode();
    // }
}
